<?php

function _comments(){

$html_comments = <<<HTML
<div id="comments" class="module">
    %s
</div>
HTML;

$html_a_comment = <<<HTML
	<user>%s: </user>%s<br>
HTML;

$html_readmore = <<<HTML
	<div class="comments-more">
		<a href="main.php?view=comments">
			xem tất cả...
		</a>
	</div>
HTML;

$comments_a_page = 10;
$result = mysql_query("SELECT * FROM comment ORDER BY date_created DESC LIMIT 0,$comments_a_page");
		
$inner_html = '';

if (mysql_num_rows($result)<=0){$inner_html = 'không có comment';} else {
	while ($record = mysql_fetch_array($result)){
		$userid = $record['user_id'];
		$username = mysql_get_username($userid);
		if ($username=='') {$username='unknown';};
		$content = $record['content'];
		
		$inner_html .= sprintf($html_a_comment,$username,$content);
	}
	if (mysql_count('comment') > $comments_a_page) {
		$inner_html .= $html_readmore;	
	}
}

printf($html_comments,$inner_html);
}

_comments();
?>